package org.itheima.controller;


import com.fasterxml.jackson.databind.node.POJONode;
import org.itheima.service.WarningsService;
import org.itheima.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("warnings")
public class WarningsController {


    @Autowired
    WarningsService warningsService;

    @PostMapping("add")
    void addWarnings(@RequestBody Map<String,String> res){
        int user_id = Integer.parseInt(res.get("user_id"));
        String message = res.get("message");
        Map<String,Object> map = ThreadLocalUtil.get();
        int issued_id = (int) map.get("id");
        System.out.println("被警告人id为："+user_id);
        System.out.println("警告信息是："+message);
        System.out.println("谁警告的："+issued_id);
        warningsService.addWarnings(user_id,message,issued_id);
    }

    @GetMapping("/find")
    List<Map<String,Object>> findById(){
        Map<String,Object> map = ThreadLocalUtil.get();
        int user_id = (int) map.get("id");
        System.out.println("被警告人id为："+user_id);
        System.out.println(warningsService.findById(user_id));
        return warningsService.findById(user_id);
    }

}
